package com.sxpi.chapter.chapter05;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 飞哥B站地址：https://space.bilibili.com/490711252
 * 记得关注和三连哦！
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2022-09-01$ 3:14$
 */
@Slf4j
public class OrderService {

    // 需要统计的订单
    public List<Order> getOrderList(){
        List<Order> list = new ArrayList<>();
        list.add(new Order("10001","飞哥",158.3));
        list.add(new Order("10002","小金",18.3));
        list.add(new Order("10003","小怪",58d));
        list.add(new Order("10004","小白",1258d));
        list.add(new Order("10005","小课",1358d));
        list.add(new Order("10006","小单",155.3));
        return list;
    }

    // 统计订单数
    public int countOrder() {
        return this.getOrderList().size();
    }

    // 统计总金额
    public double sumOrder() {
        List<Order> orderList = this.getOrderList();
        Double aDouble = orderList.stream().map(a -> a.getPrice())
                .reduce((a, b) -> a + b).get();
        return aDouble;
    }
}
